import React, { useState, useEffect } from 'react';

import { NavBar, Icon, Grid } from 'antd-mobile';

import { createForm } from 'rc-form'

import './commonPoblem.scss';

import { GetTutorFaqOfTutor, GetParentFaqOfTutor } from "@/api/login.js"; // login api

function CommonPoblem (props) {
    let [knowHtml, setKnowHtml] = useState("");

    // 家教 常见问题
    function axiosGetTutorFaqOfTutor () {
        GetTutorFaqOfTutor().then(res => {
            if (res.code == "000000") {
                console.log('res ----->>>', res)
                setKnowHtml(res.responseData)
            }
        })
            .catch((err) => {
                console.log('err ----->>>', err)
            })
    }

    // 家长 常见问题
    function axiosGetParentFaqOfTutor () {
        GetParentFaqOfTutor().then(res => {
            if (res.code == "000000") {
                console.log('res ----->>>', res)
                setKnowHtml(res.responseData)
            }
        })
            .catch((err) => {
                console.log('err ----->>>', err)
            })
    }


    useEffect(() => {
        // 用户角色判断
        if (sessionStorage.getItem('roleVal') == 'TUTOR') {
            axiosGetTutorFaqOfTutor()
        } else {
            axiosGetParentFaqOfTutor()
        }
    }, [])


    return (
        <div className="common-poblem">
            <div className="page-title common-poblem-tit">
                <NavBar
                    mode="light"
                    icon={<Icon type="left" />}
                    onLeftClick={() => {
                        if (sessionStorage.getItem('roleVal') == 'TUTOR') {
                            props.history.push({
                                pathname: '/mainTutor',
                                query: {
                                    selectedTab: 'my'
                                }
                            })
                        } else {
                            props.history.push({
                                pathname: '/main',
                                query: {
                                    selectedTab: 'my'
                                }
                            })
                        }


                    }}
                >
                    常见问题解答
                </NavBar>
            </div>
            <div className="page-content common-poblem-con" dangerouslySetInnerHTML={{ __html: knowHtml }}>

            </div>
        </div>
    );
}

CommonPoblem = createForm()(CommonPoblem);

export default CommonPoblem;